package com.jackrain.nea.fc.vp.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * VIP积分调整Mapper
 *
 * @author wuwenxue
 * @date 2017/11/17
 **/
@Mapper
public interface ViewCinteadjMapper {

    /**
     * 根据传入json条件查询主表记录
     *
     * @param id 查询判断条件
     * @return List
     */
    @SelectProvider(type = ViewCInteadjSql.class, method = "findCInteadj")
    List<HashMap> findAllInteadj(@Param("id") Object[] id);

    class ViewCInteadjSql {
        public String findCInteadj(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("DOCNO,STATUSTIME,VP_C_VIP_ID,VP_C_VIPTYPEGROUP_ID,INTEADJ,REMARK");
                    FROM("VP_C_INTEADJ");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }
    }

    /**
     * 根据vip和vip类型在vip账户下查询VIP卡号
     *
     * @param vipID          vip
     * @param viptypegroupID vip类型
     * @return 卡号
     */
    @Select("select ECODE from VP_C_VIP_ACC where VP_C_VIP_ID=#{vipID} and VP_C_VIPTYPEGROUP_ID=#{viptypegroupID}")
    String vipEcode(@Param("vipID") Long vipID, @Param("viptypegroupID") Long viptypegroupID);

    /**
     * 外键关联【VP_C_VIPTYPEGROUP】查询VIP类型
     *
     * @param viptypegroupID VIP类型ID
     * @return String
     */
    @Select("SELECT ECODE FROM VP_C_VIPTYPEGROUP WHERE ID=#{viptypegroupID}")
    String vipType(Long viptypegroupID);
}
